// pages/activityDetail/activityDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    id:undefined,
    drawNum: undefined,
    showPersent:0,
    recordList:[
      {
        nickname:"ceshi1yonghu",
        drawingNum:30,
        presentFlag:1,
        goodsFlag:0
      }
    ],
    activity:{
      title:'cehsi',
      content:'ceshi',
      outNum: 50,
      presentList:[
        {
          name:'present1',
          imageUrl:'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg'
        }
      ]
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id

    wx.$request(true,"/activity/findActivity/"+this.data.id,"GET",null)
    .then(res=>{
      this.setData({
        "activity.title":res.title,
        "activity.content":res.content,
        "activity.outNum":res.outNum,
        "activity.presentList":res.presentList,
      })
    })

    wx.$request(true,"/activity/findDrawingCardList/"+this.data.id,"POST",null)
    .then(res=>{
      this.setData({
        recordList:res
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  showPredicate(){
    this.setData({
      show: !this.data.show,
      drawNum: 0
    })
  },

  predicate(){
    wx.$request(true,"/activity/calcDrawing","POST",{
      activityId:this.data.id,
      drawNum:this.data.drawNum
    })
    .then(res=>{
      this.setData({
        showPersent:res
      })
    })
  },

  saveRecord(opt){
    var type = opt.currentTarget.dataset.type
    wx.$request(true,"/activity/saveRecord","POST",{
      activityId:this.data.id,
      drawingNum:this.data.drawNum,
      presentFlag:type
    })
    .then(
      this.showPredicate()
    )
  },

  goodClik(type){
    var tmp = this.data.recordList
    tmp[type.currentTarget.dataset.index].goodsFlag = type.currentTarget.dataset.type
    this.setData({
      recordList:tmp
    })

    wx.$request(true,"/social/clickGood","POST",{
      resourceId:tmp[type.currentTarget.dataset.index].id,
      goodFlag:type.currentTarget.dataset.type
    })
    .then(res=>{})
  },
  turnComment(param){
    wx.reLaunch({
      url: '/pages/comment/comment?id='+param.currentTarget.dataset.id,
    })
  }
})